{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "日期：2022.9.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found = []\n",
    "found.append('e')\n",
    "found.append('i')\n",
    "found.append('o')\n",
    "len(found)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['u']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "found = []\n",
    "if 'u' not in found:\n",
    "    found.append('u')\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "s\n",
      "s\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    " print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        if letter not in found:\n",
    "            found.append(letter)\n",
    "for vowel in found:\n",
    " print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nums = [1,2,3,4]\n",
    "nums.remove(3)\n",
    "nums"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nums = [1,2,4]\n",
    "nums.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "nums.extend([3,4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "phrase = \"Don't panic\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(o)\n",
    "plist.remove(\"'\")\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "plist.insert(2,plist.pop(3))\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "first = [1,2,3,4,5]\n",
    "first"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#本周学习内容\n",
    "\n",
    "1.数值（number）\n",
    ">a，定义\n",
    ">b，方法\n",
    "\n",
    "2.字符串\n",
    ">a，定义\n",
    ">b，方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "199"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "99+100"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##1.数值\n",
    "\n",
    ">1.对数值的分类\n",
    "\n",
    ">>1.整数（int）\n",
    ">>2.浮点型（float）\n",
    ">>3.复数（complex）\n",
    "\n",
    ">2.数值的运算法则(https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#整型\n",
    "a = 99\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "#浮点型\n",
    "b = 99.9\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "198.9 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "c = a+b\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "#复数(虚数)\n",
    "d= 2+3j\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#2.字符串（str）\n",
    "https://docs.python.org/3/library/stdtypes.html#string-methods\n",
    "\n",
    ">1.定义\n",
    ">2.方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#\n",
    ">\n",
    ">>\n",
    ">\n",
    ">"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18 18\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "a = 18\n",
    "b = '18'\n",
    "print(a,b)\n",
    "print(type(a),type(b))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 关于单引号和双引号\n",
    "\n",
    "#解决方案1\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#解决方案2     \\后面的内容是“符号”，转义，\\自动消失\n",
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#正则表达式，有兴趣自学"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"hello\n",
    "world\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#三个引号，可以包含任何文本\n",
    "#作用：\n",
    "#1.保持原数据的结构，包含符号，换行等。\n",
    "#2.可以用来做代码注释。\n",
    "NFU_招投标_HTML = "
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world!\n"
     ]
    }
   ],
   "source": [
    "## 三个引号来代码注释\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "\n",
    "南方学院学校要闻 = \"https://www.nfu.edu.cn/xxyw/index\"\n",
    "页面后缀 = \".htm\"\n",
    "page = 5\n",
    "\n",
    "\"\"\"\n",
    "for i in range(page):\n",
    "    print(南方学院学校要闻 + str(i) + 页面后缀)  # 字符串拼接\n",
    "    random_num = random.randint(1,10)\n",
    "    print(\"该次停留\",random_num,'秒')\n",
    "    time.sleep(random_num)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello world!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 字符串的运算法则\n",
    ">1.字符串的拼接\n",
    "\n",
    ">2.<font color=\"red\">字符串的有序性</font>\n",
    ">>a.取值\n",
    ">>b.切片\n",
    "\n",
    ">3.enumerate:枚举\n",
    "\n",
    ">4.in可以查询成员对象是否存在"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'helloworld'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字符串的拼接\n",
    "\"hello\"+\"world\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-23-b5876993e807>, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-23-b5876993e807>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m    for i in range[\"Alex\"，\"tom\"]:\u001b[0m\n\u001b[1;37m                         ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "# 实践\n",
    "text = (\"你好，\")\n",
    "for i in range[\"Alex\"，\"tom\"]:\n",
    "    result = text+i\n",
    "    print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*取值\n",
    "1.取单个值\n",
    "2.切片，取多个连续的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "#字符串的有序性\n",
    "地址 = \"广州市从化区温泉大道882号广州南方学院\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[0:2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'从化区'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "地址[3:6]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 重要！！！！(什么新媒体，前面的是什么)\n",
    "#实践：请检查 广州是否在 地址 里面？\n",
    "#检查i是否是广，然后判断i[index+1]下一个索引值的内容是否是州\n",
    "\n",
    "#方法：\n",
    "for index,value in enumerate(地址):\n",
    "    if value == \"广\":\n",
    "        if 地址[index+1] == \"州\":\n",
    "            print(\"存在 广州 这个文本\"）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#方法2，in 可以查询成员变量的，只能查询是否存在，不能查询次数\n",
    "print(\"广州\" in 地址)\n",
    "print(\"Alex\" in 地址)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#回去课后学习字符串方法（）\n",
    "## 1. 首字母变大写\n",
    "## 2.检查字符出现的次数\n",
    "print(\"alex\".capitalize())\n",
    "地址.count(\"广州\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
